<?php
/*
*	Kleophatra - Open Source Content Management System
*	------------------------------------------------------------------------
*	Copyright (C) 2007-2010, Sergio Milardovich <smilardovich@yahoo.com.ar>
*	This program is Free Software.
*
*	@package	Kleophatra
*	@subpackage	/lib
*	@license	http://www.gnu.org/copyleft/gpl.html GNU/GPL License 2.0
*	@author		Sergio Milardovich <smilardovich@yahoo.com.ar>
*	@link		http://www.kleophatra.org
*/
	class kleoadmin extends kleotemplate {
		/*		
		 *	This is an experimental API for administration pannel, so do not expect
		 *	to find loads of documentation.		
		 */

		/*
		 * Check for the hole actions and if one of them is in the right place, run it
		 */
		function do_actions(){
			if(!isset($_GET['file'])){
				$_GET['file'] = null;
			}
			foreach($this->actions as $action){
				if(substr($_GET['file'],0,-4) == $action['place'] or $action['place'] == '*'){
					switch($action['type']){
						case 'onpost':
							if(!empty($_POST[0])){
								$this->do_action($action['file'],$action['callback']);
							}
						break;
						case 'once':
							if(!isset($_SESSION[md5($action['place'].$action['file'].$action['callback'])])){
								$this->do_action($action['file'],$action['callback']);
								$_SESSION[md5($action['place'].$action['file'].$action['callback'])] = true;
							}
						break;
						case 'nopost':
							if(empty($_POST[0])){
								$this->do_action($action['file'],$action['callback']);
							}
						break;
					}
				}
			}
		}
		function do_action($file,$callback){
			require_once $file;
			eval("$callback;");
		}

		function check_plugins(){
			$this->apploadlib(KLEO_LIB_DIR.'plugins.lib.php', "kleoplugins", $p);
			$plugins = $this->list_dir_files(KLEO_PLUGINS_DIR);
			foreach($plugins as $plugin){
				if($p->is_active_plugin($plugin)){
					require_once KLEO_PLUGINS_DIR.$plugin.'/main.php';
					$actions = new $plugin();
					if(isset($actions->actions)){
						foreach($actions->actions as $action){
							$this->actions[] = $action;
						}
					}
				}
			}
		}
		function check_modules(){
			$modules = $this->list_dir_files(KLEO_MODULES_DIR);
			$this->apploadlib(KLEO_LIB_DIR.'modules.lib.php', "kleomodules", $m);
			foreach($modules as $module){
				if(!$m->is_active_module($module)){
					$m->add_module($module, rand(), 0);
				}
			}
		}
	}
?>
